//========================================================================
// *作者：海盗猫  主页：ilplay.com
// *脚本：HDMExcelRead
// *描述：
// *?2021 MYJL . All rights reserved.
//* ======================================================================

using Newtonsoft.Json.Linq;
using NPOI.SS.UserModel;

namespace HDMCode.Excel
{
	public class HDMExcelRead
	{
        /// <summary>
        /// 读取副表
        /// </summary>
        /// <param name="xlslName">配置表名称</param>
        /// <returns></returns>
        public static JToken ReadSheel(string xlslName)
        {
            try
            {
                ExcelToJson excelPath = new ExcelToJson($"{xlslName}");
                var xlslDate = JToken.Parse(excelPath.outJson);
                return xlslDate;
            }
            catch (System.Exception)
            {
                return "null";
            }
        }

        /// <summary>
        /// 读取副表
        /// </summary>
        /// <param name="xlslName">配置表名称</param>
        /// <param name="sheet">副表</param>
        /// <returns></returns>
        public static JToken ReadSheel(string xlslName, string sheet) 
		{
            try
            {
                ExcelToJson excelPath = new ExcelToJson($"{xlslName}");
                var xlslDate = JToken.Parse(excelPath.outJson);
                var sheetDate = xlslDate[0][sheet];
                return sheetDate;
            }
            catch (System.Exception)
            {
                return "null";
            }
        }

        /// <summary>
        /// 读取ID
        /// </summary>
        /// <param name="xlslName">配置表名称</param>
        /// <param name="sheet">副表</param>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public static JToken ReadSheel(string xlslName, string sheet, string id)
        {
            try
            {
                ExcelToJson excelPath = new ExcelToJson($"{xlslName}");
                var xlslDate = JToken.Parse(excelPath.outJson);
                var idDate = xlslDate[0][sheet][id];
                return idDate;
            }
            catch (System.Exception)
            {
                return "null";
            }
        }

        /// <summary>
        /// 类型数据
        /// </summary>
        /// <param name="xlslName">配置表名称</param>
        /// <param name="sheet">副表</param>
        /// <param name="id">ID</param>
        /// <param name="type">类型</param>
        /// <returns></returns>
        public static string ReadSheel(string xlslName, string sheet, string id,string type)
        {
            try
            {
                ExcelToJson excelPath = new ExcelToJson($"{xlslName}");
                var xlslDate = JToken.Parse(excelPath.outJson);
                var typeDate = xlslDate[0][sheet][id][type].ToString();
                return typeDate;
            }
            catch (System.Exception)
            {
                return "null";
            }
        }
    }
}


